<script setup lang="ts">
const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false,
  },
});
const emit = defineEmits(["update:modelValue"]);
const selectMerchant = async (merchant: string) => {
  // 用户关联信息查询
  const res = await useApi().user.queryUserRelation({
    relationType: merchant,
  });
  const data = res.data;
  userStore().setRelation({
    relationType: merchant,
    ...data,
  });
  emit("update:modelValue", false);
  // 查询只有一个商户信息的情况下 是否跳转审核页面
  if (data.operationFlag === "HOME_PAGE" && data.relationList.length === 1) {
    userStore().setRegInfo({
      ...data.relationList[0],
    });
    const res2 = await useApi().merchant.queryDetail(
      {
        relationNo: data.relationList[0].relationNo,
        relationType: merchant,
      },
      merchant
    );
    const data2 = res2.data;
    // 审核状态=>审核通过 打款认证状态=>认证成功
    if (data2.auditStatus != "PASS" && data2.payAuthStatus != "AUTH_SUCCESS") {
      location.href = "/open/website/examine";
      return;
    }
  }
  goPage(data.operationFlag);
};

const goPage = (operationFlag: string) => {
  switch (operationFlag) {
    // 跳转开通注册页
    case "OPEN_PAGE":
      location.href = "/open/website/register";
      break;
    // 列表页(有新增入口)
    case "LIST_ADD_PAGE":
      location.href = "/open/website/multiple?add=1";
      break;
    // 列表页
    case "LIST_PAGE":
      location.href = "/open/website/multiple";
      break;
    // 跳转首页
    case "HOME_PAGE":
      location.href = "/open/";
      break;
  }
};
</script>
<template>
  <div class="mask" v-if="props.modelValue">
    <div class="merchant">
      <div class="merchant-item" @click="selectMerchant('MERCHANT')">
        <div class="go-btn">
          <span>选择商户</span>
          <img src="/images/layouts/arrow-white.png" alt="立即体验" />
        </div>
      </div>
      <div class="merchant-item" @click="selectMerchant('AGENT')">
        <div class="go-btn">
          <span>选择服务商</span>
          <img src="/images/layouts/arrow-white.png" alt="立即体验" />
        </div>
      </div>
      <img
        @click="emit('update:modelValue', false)"
        src="/images/index/X.png"
        alt=""
        class="close"
      />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.mask {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  .merchant {
    display: flex;
    align-items: center;
    position: relative;
    .close {
      position: absolute;
      top: -60px;
      right: 36px;
      width: 36px;
      height: 36px;
      cursor: pointer;
      z-index: 3;
    }
    .merchant-item {
      cursor: pointer;
      width: 496px;
      height: 374px;
      background-size: cover;
      background-repeat: no-repeat;
      transition: transform 0.3s ease;
      position: relative;
      &:first-child {
        background-image: url("/images/index/reg1.png");
        margin-right: 92px;
        &:hover {
          transform: translateY(-10px);
          background-image: url("/images/index/reg-select1.png");
          .go-btn {
            background: #e12010;
          }
        }
      }
      &:nth-child(2) {
        background-image: url("/images/index/reg2.png");
        margin-right: 92px;
        &:hover {
          transform: translateY(-10px);
          background-image: url("/images/index/reg-select2.png");
          .go-btn {
            background: #e12010;
          }
        }
      }
      img {
        width: 100%;
        height: 100%;
      }
      .go-btn {
        transition: all 0.3s ease;
        position: absolute;
        bottom: -27px;
        left: 50%;
        margin-left: -95px;
        width: 190px;
        height: 54px;
        background: #959595;
        border-radius: 4px;
        font-weight: 400;
        font-size: 15px;
        color: #ffffff;
        letter-spacing: 1px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        img {
          width: 19px;
          height: 9px;
          margin-left: 8px;
        }
      }
    }
  }
}
</style>
